package org.kzwl.book.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.QueryThearBO;
import org.kzwl.comm.pojo.bo.SaveThearBO;
import org.kzwl.comm.pojo.bo.ThearApprovalBO;
import org.kzwl.comm.pojo.bo.ThearAuditBO;
import org.kzwl.comm.pojo.bo.thear.AddThearBO;
import org.kzwl.comm.pojo.bo.thear.ThearDetails;
import org.kzwl.comm.pojo.bo.thear.ThearQueryBasicBO;
import org.kzwl.comm.pojo.dto.ThearApprovalDTO;
import org.kzwl.comm.pojo.dto.thear.ThearDetailsDTO;
import org.kzwl.comm.utils.MyUtils;
import org.kzwl.entity.web.Thear;
import org.kzwl.service.web.ThearService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/thear")
@Api("PC风采展示")
public class ThearController {

    @Autowired
    ThearService thearService;

    @ApiOperation(value = "admin-添加一条风采展示信息")
    @PostMapping("/saveOne")
    public ResponseData<Void> saveOne(@RequestBody SaveThearBO saveThearBO)
    {
        return thearService.saveOne(saveThearBO);

    }

    @ApiOperation(value = "admin-查询风采展示信息")
    @PostMapping("/queryPage")
    public ResponseData<IPage<Thear>> queryPage(@RequestBody QueryThearBO queryThearBO)
    {
        return thearService.queryPage(queryThearBO);
    }

    @ApiOperation(value = "admin-查询一条风采信息")
    @PostMapping("/queryOne")
    public ResponseData<Thear> queryOne(@RequestBody Long Id)
    {
        return thearService.queryOne(Id);
    }

    @ApiOperation(value = "admin-删除一条风采信息")
    @PostMapping("/deleteId")
    public ResponseData<Void> deleteId(@RequestBody Long Id)
    {
        return thearService.deleteId(Id);
    }
    @ApiOperation(value = "admin-修改一条风采信息")
    @PostMapping("/updateId")
    public ResponseData<Void> updateId(@RequestBody Thear thear)
    {
        return thearService.updateId(thear);
    }

    @ApiOperation(value = "风采展示基础查询")
    @PostMapping("/queryBasic")
    @Valid
    public ResponseData<IPage<Thear>> queryBasic(@RequestBody @Valid ThearQueryBasicBO thear)
    {
        IPage<Thear> page = thearService.queryBasic(thear);
        page.getRecords().forEach(l -> {
            l.setCuThearCenter(MyUtils.regExHtml(l.getCuThearCenter()));
            l.setCuThearCenter(l.getCuThearCenter().substring(0, Math.min(l.getCuThearCenter().length(), 30)));
        });
        return new ResponseData<>(page);
    }

    @ApiOperation(value = "风采展示详细查询")
    @PostMapping("/queryDetails")
    @Valid
    public ResponseData<ThearDetailsDTO> queryDetails(@RequestBody @Valid ThearDetails bo)
    {
        ThearDetailsDTO thear = thearService.queryDetails(bo);
        return new ResponseData<>(thear);
    }

    @ApiOperation(value = "风采展示发布")
    @PostMapping("/addThear")
    @Valid
    public ResponseData<Void> addThear(@RequestBody @Valid AddThearBO bo)
    {
        thearService.addThear(bo);
        return new ResponseData<>();
    }

    @ApiOperation(value = "后台查询审批")
    @PostMapping("/queryApproval")
    public ResponseData<IPage<ThearApprovalDTO>> queryApproval(@RequestBody @Valid ThearApprovalBO thearApprovalBO)
    {
        return thearService.queryApproval(thearApprovalBO);
    }

    @ApiOperation(value = "审批操作")
    @PostMapping("/thearAudit")
    public ResponseData<Void> thearAudit(@RequestBody ThearAuditBO thearAuditBO)
    {
        return thearService.thearAudit(thearAuditBO);
    }

}
